package com.einmeer.vo;

import lombok.Getter;

/**
 * @author 芊嵛
 * @date 2024/3/18
 */
@Getter
public class ResultJson<T> {
    private Integer code;
    private T content;
    private String message;

    public ResultJson(Integer code, T content, String message) {
        this.code = code;
        this.content = content;
        this.message = message;
    }

    public static <T> ResultJson<T> getInstance(ResultCode resultCode, T content, String message) {
        return new ResultJson<>(resultCode.getId(), content, message);
    }
    public static <T> ResultJson<T> success(T content,String message){
        return getInstance(ResultCode.SUCCESS,content,message);
    }

    public static <T> ResultJson<T> success(T content){
        return success(content,null);
    }


    public static <T> ResultJson<T> failed(T content,String message){
        return getInstance(ResultCode.FAILED,content,message);
    }

    public static <T> ResultJson<T> failed(String message){
        return failed(null,message);
    }

    public static <T> ResultJson<T> unlogin(String message){
        return getInstance(ResultCode.UNLOGIN,null,message);
    }

    public static <T> ResultJson<T> forbid(){
        return getInstance(ResultCode.FORBID,null,"该用户无次权限");
    }
}
